<%@ page language="java" import="java.text.*,java.util.*,ct.zxd.db.*,ct.zxd.bean.*,net.sf.json.JSONArray,net.sf.json.JSONObject" pageEncoding="utf-8"
contentType="text/html"
%>
<html>
  <head>
  	<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
    <title>查询结果</title>
  </head>
  <%
   Dao dao=new Dao();
   int pageSize=5;//页大小   
   int totalPage=1;//总页数
   
   int displayPage=1;//显示页
   String pages=request.getParameter("pages");//用户选择的显示页
   if(pages!=null){
     displayPage=Integer.parseInt(pages); 
     if(displayPage<1)displayPage=1;
     if(displayPage>totalPage)displayPage=totalPage;    
   }    
   
   List<Map<String,Object>> list=dao.getTableByid("ordertable", "1",null);//获取数据   
   
   %>
  <body>
    查询结果
    <table border="1" width="400">
     <tr>
       <th>状态</th> <th>时间</th> <th>菜单</th> <th>金额</th> <th>地址</th> <th>类型</th>
     </tr>
     <%
       if(list!=null){
       for(Map<String,Object> map : list){
       		
       		String timestr = map.get("time").toString();
       		long time = Long.parseLong(timestr);
       		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
   			String dateString = formatter.format(new Date(time)); 			
   			
   			JSONObject jb = JSONObject.fromObject(map.get("list").toString());
        	JSONArray ja = jb.getJSONArray("order");

      %>
      <tr>
      <td><%=map.get("status").toString()%></td>
       <td><%=dateString%></td>
       <td><%for (int i = 0; i < ja.size(); i++) {%>
          <%=ja.getJSONObject(i).getString("name")%>
          <%="  x"+ja.getJSONObject(i).getString("quantity")%>
          <%="     "+ja.getJSONObject(i).getString("price") %>
          <br>
       <%}%></td> 
       <td><%=map.get("money").toString()%></td>
       <td><%=map.get("address").toString()%></td>
       <td><%=map.get("type").toString()%></td>
       </tr>
     <% } } %>
   </table>
   <a href="Student_query.jsp?pages=1">第一页</a> 
   
   <% if(displayPage<totalPage){%>
    <a href="Student_query.jsp?pages=<%=displayPage+1%>">下一页</a>
   <%}%>
   
   <%if(displayPage>1) {%>
    <a href="Student_query.jsp?pages=<%=displayPage-1%>">上一页</a>
   <%}%>
   
   <a href="Student_query.jsp?pages=<%=totalPage%>">最后一页</a> 
 
  </body>
</html>
